package com.sidianzhong.sdz.service.impl;

import com.github.pagehelper.PageHelper;
import com.sidianzhong.sdz.mapper.*;
import com.sidianzhong.sdz.model.*;
import com.sidianzhong.sdz.service.*;
import com.sidianzhong.sdz.utils.PageInfo;
import com.sidianzhong.sdz.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;


/**
* Created by hxgqh on 2016/1/7.
*/
@Service
@Transactional
public class WebInspectionrecordServiceImpl implements WebInspectionrecordService{
    protected static final Logger LOG = LoggerFactory.getLogger(WebInspectionrecordServiceImpl.class);

    // 将所有的modelMapper注入
    @Autowired
    private WebInspectionrecordMapper webInspectionrecordMapper;


    @Override
    public WebInspectionrecord create(WebInspectionrecord item) {

         webInspectionrecordMapper.insert(item);
         return item;
    }

    @Override
    public int delete(Integer id) {
        return webInspectionrecordMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(WebInspectionrecord item) {

        return webInspectionrecordMapper.updateByPrimaryKeySelective(item);
    }

    @Override
    public WebInspectionrecord get(Integer id) {
        return webInspectionrecordMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<WebInspectionrecord> getListWithPaging(Integer pageNum, Integer pageSize,
                                                           String sortItem, String sortOrder,WebInspectionrecord item){

        WebInspectionrecordExample  example = new WebInspectionrecordExample();
        WebInspectionrecordExample.Criteria criteria = example.createCriteria();
        if(item.getRecordtime() != null ){
            criteria.andRecordtimeEqualTo(item.getRecordtime());
        }
        if(item.getRecordnote() != null ){
            criteria.andRecordnoteEqualTo(item.getRecordnote());
        }

        example.setOrderByClause(Tools.humpToLine(sortItem)+" "+sortOrder);
        PageHelper.startPage(pageNum, pageSize);
        List< WebInspectionrecord> list = this.webInspectionrecordMapper.selectByExample(example);
        PageInfo result = new PageInfo(list);

        return result;

    }

    @Override
     public List<WebInspectionrecord> getListByTime(Integer pageNum, Integer pageSize,
                                                            String startTime,String endTime,String equipmenttypekey,String equipmentkey){
        PageHelper.startPage(pageNum, pageSize);
        List< WebInspectionrecord> list = this.webInspectionrecordMapper.selectByTime(startTime,endTime,equipmenttypekey,equipmentkey);
//        PageInfo result = new PageInfo(list);

        return list;

     }

}
